/*
 * Qinlan Shen
 * November 8, 2010
 * Pd. 8
 * 
 * Script, based off of a fanmade Sakuya non-spell.  Difficulty and time limit
 * can be adjusted.
 * 
 */


import java.awt.Image;
import java.util.ArrayList;

public class SakuNon extends RoseScript
{
	private int frame2;
	private int angle;
	private int angleC;
	private int radius;
	public SakuNon(int d, int t)
	{
		super(d + 6, t);
		frame2 = -50;
		angle = 0;
		angleC = 0;
		radius = 150;
	}

	public ArrayList<PointItem> run(Rose rose, Character player, int frame,	ArrayList<Enemy> enemies, ArrayList<PointItem> points, ArrayList<Image> packets, Image point)
	{
		
		incrementTime(frame);		
		frame2++;
		
		if (frame == 0)
			rose.moveUsingFrames(320, 120, 60);
		else if (frame % 120 == 0)
			rose.randomMove(100, 25, 60);
		
		if (frame > 80)
		{
			if (difficulty <= 16 && frame % ((21 - difficulty) * 2) ==  0 || difficulty > 16 && frame % (21-difficulty) == 0)
				attack(rose, player, enemies, packets);
			
			if (frame2 == 0)
				angle = -90;
			else if (frame2 == 55)
				angle = 90;
			else if (frame2 > 80)
				frame2 = -50;
			if (frame2 >= 0 && frame2 < (difficulty - 6) * 1.5)
			{	
				wave(rose, player, enemies, packets);
				angle += 120/25;
			}
			else if (frame2 >= 55 && frame2 < 55 + (difficulty - 6) * 1.5)
			{
				wave(rose, player, enemies, packets);
				angle -= 120/25;
			}
		}
		if (time < 0)
			points = endScript(point, rose, player, enemies);
		
		return points;
		
	}
	
	public void attack(Rose rose, Character player, ArrayList<Enemy> enemies, ArrayList<Image> packets)
	{
		angleC+=5;
		for (int i = 0; i < difficulty - 4; i++)
		{
			enemies.add(new PacketSA(packets.get(0), 3, (int)Math.round(rose.getX()), (int)Math.round(rose.getY()), 3, angleC + i * 30));
			enemies.add(new PacketSA(packets.get(0), 3, (int)Math.round(rose.getX()), (int)Math.round(rose.getY()), 3, -angleC + i * 30));
		}
	}
	
	public void wave(Rose rose, Character player, ArrayList<Enemy> enemies, ArrayList<Image> packets)
	{
		int angleB = 0;
		for (int j = 0; j < difficulty; j++)
		{
			enemies.add(new PacketSA(packets.get(0), 3, (int)Math.round(rose.getX() + radius * Math.sin(Math.toRadians(angle))), (int)Math.round(rose.getY() + radius * Math.cos(Math.toRadians(angle))), 3, 0));
			((PacketSA) enemies.get(enemies.size()-1)).setAngle(enemies.get(enemies.size()-1).getAngleToPlayer(player) + angleB);
			angleB += 360/difficulty;
		}	
	}
	
}